package com.jinke.api.modules.ums.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import com.jinke.api.common.api.CommonPage;
import com.jinke.api.common.api.CommonResult;
import com.jinke.api.common.util.RSAUtils;
import com.jinke.api.common.util.SHA256Util;
import com.jinke.api.modules.app.controller.param.SellerUserDayParam;
import com.jinke.api.modules.app.enums.ChannelStatus;
import com.jinke.api.modules.app.enums.MemberType;
import com.jinke.api.modules.app.request.AdminUpdateRequest;
import com.jinke.api.modules.app.service.OrderService;
import com.jinke.api.modules.ums.dto.*;
import com.jinke.api.modules.ums.model.*;
import com.jinke.api.modules.ums.request.AllotChannelRequest;
import com.jinke.api.modules.ums.request.AllotSellerRequest;
import com.jinke.api.modules.ums.request.UserChannelRequest;
import com.jinke.api.modules.ums.service.*;
import com.jinke.api.modules.ums.vo.UmsAdminVO;
import com.jinke.api.modules.ums.vo.UserChannelByServiceCodeVO;
import com.jinke.api.modules.ums.vo.UserChannelVO;
import com.jinke.api.modules.user.model.UmsAdminPriceRuleRelation;
import com.jinke.api.modules.user.service.UmsAdminPriceRuleRelationService;
import com.jinke.api.security.util.AdminUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.jinke.api.modules.app.controller.param.CompanySellerProfitParam;
import com.jinke.api.modules.ums.vo.SellerVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.security.Principal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 后台用户管理
 * Created by macro on 2018/4/26.
 */
@Slf4j
@Controller
@Api(tags = "UmsAdminController")
@Tag(name = "后台用户管理", description = "后台用户管理")
@RequestMapping("/admin")
public class UmsAdminController {
    @Value("${jwt.tokenHeader}")
    private String tokenHeader;
    @Value("${jwt.tokenHead}")
    private String tokenHead;
    @Autowired
    private UmsAdminPriceRuleRelationService umsAdminPriceRuleRelationService;
    @Autowired
    private UmsAdminService adminService;
    @Autowired
    private UmsAdminRoleRelationService umsAdminRoleRelationService;
    @Autowired
    private UmsRoleResourceRelationService umsRoleResourceRelationService;
    @Autowired
    private UmsResourceService umsResourceService;
    @Resource
    private UserChannelService channelUserService;
    @Resource
    private ChannelPlatformService channelPlatformService;
    @Resource
    private ChannelService channelService;
    @Resource
    private ChannelCarrierService channelCarrierService;
    @Resource
    private OrderService orderService;

    private final static String WZ_EMAIL = "admin@163.com";
    private final static String WZ_EMAIL2 = "403379112@qq.com";
    private final static String NINA_EMAIL = "945629909@qq.com";


    @ApiOperation("给用户分配角色")
    @RequestMapping(value = "/role/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateRole(@Validated @RequestBody RoleUpdateParam roleUpdateParam) {


        Integer adminId = roleUpdateParam.getAdminId();
        getUmsAdmin(adminId);
        int count = adminService.updateRole(adminId, roleUpdateParam.getRoleIds());
        if (count >= 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "用户注册/添加账号")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<UmsAdmin> register(@Validated @RequestBody UmsAdminParam umsAdminParam) {
        if (umsAdminParam.getMemberType()==null){
            umsAdminParam.setMemberType(MemberType.USER);
        }
        UmsAdmin umsAdmin = adminService.register(umsAdminParam);
        if (umsAdmin == null) {
            return CommonResult.failed();
        }
        return CommonResult.success(umsAdmin);
    }

    @ApiOperation(value = "登录以后返回token")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult login(@Validated @RequestBody UmsAdminLoginParam umsAdminLoginParam) {
        UmsAdminLoginParam encryptLoginParam = null;
        try {
            encryptLoginParam = JSONObject.parseObject(
                    Optional.of(
                            RSAUtils.decryptByPrivateKey(umsAdminLoginParam.getEncryptData(), RSAUtils.getPrivateKey(RSAUtils.ENCRYPT_PRIVATE_KEY))
                    ).orElse("{}"),
                    UmsAdminLoginParam.class);
            log.info("解密后的数据:[{}]", encryptLoginParam);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        String username = encryptLoginParam.getUsername();
        UmsAdmin umsAdmin = adminService.getOne(new LambdaQueryWrapper<UmsAdmin>().eq(UmsAdmin::getUsername, username)
                .eq(UmsAdmin::getMemberType, MemberType.USER)
        );
        if (umsAdmin == null) {
            CommonResult.failed("非法操作");
        }

        String token = adminService.login(username, encryptLoginParam.getPassword());
        if (token == null) {
            return CommonResult.validateFailed("用户名或密码错误");
        }

        Map<String, String> tokenMap = new HashMap<>();
        tokenMap.put("token", token);
        tokenMap.put("tokenHead", tokenHead);


        return CommonResult.success(tokenMap);
    }

    @ApiOperation(value = "刷新token")
    @RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult refreshToken(HttpServletRequest request) {
        String token = request.getHeader(tokenHeader);
        String refreshToken = adminService.refreshToken(token);
        if (refreshToken == null) {
            return CommonResult.failed("token已经过期！");
        }
        Map<String, String> tokenMap = new HashMap<>();
        tokenMap.put("token", refreshToken);
        tokenMap.put("tokenHead", tokenHead);
        return CommonResult.success(tokenMap);
    }

    @ApiOperation(value = "获取当前登录用户信息")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getAdminInfo(Principal principal) {
        if (principal == null) {
            return CommonResult.unauthorized(null);
        }
        String username = principal.getName();
        UmsAdmin umsAdmin = adminService.getAdminByKeyword(username);
        UmsAdminVO umsAdminVO = new UmsAdminVO();
        BeanUtils.copyProperties(umsAdmin, umsAdminVO);

        List<UmsRole> roleList = adminService.getRoleList(umsAdmin.getId());
        if (CollUtil.isNotEmpty(roleList)) {
            List<String> roles = roleList.stream().map(x -> {
                return x.getId().toString();
            }).collect(Collectors.toList());
            umsAdminVO.setRoles(roles);
            List<Integer> roleIds = roleList.stream().map(x -> {
                return x.getId();
            }).collect(Collectors.toList());
            Set<Integer> sourceIds = umsRoleResourceRelationService.list(new LambdaQueryWrapper<UmsRoleResourceRelation>()
                            .in(UmsRoleResourceRelation::getRoleId, roleIds))
                    .stream().map(UmsRoleResourceRelation::getResourceId).filter(Objects::nonNull).collect(Collectors.toSet());
            if (CollectionUtil.isNotEmpty(sourceIds)) {
                List<UmsResource> umsResources = umsResourceService.list(new LambdaQueryWrapper<UmsResource>()
                        .in(UmsResource::getId, sourceIds)
                        .isNotNull(UmsResource::getCode)
                        .select(UmsResource::getCode));
                umsAdminVO.setResources(umsResources);
            }

        }


        return CommonResult.success(umsAdminVO);
    }

    @ApiOperation(value = "登出功能")
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult logout() {
        return CommonResult.success(null);
    }

    @ApiOperation(value = "生成任意用户Token")
    @RequestMapping(value = "/token/build/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult buildToken(@PathVariable Integer id) {
        return adminService.buildToken(id);
    }

    @ApiOperation("根据用户名或姓名分页获取用户列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<UmsAdminVO>> list(UmsAdminListParam request) {
        request.setMemberType(MemberType.USER);
        return adminService.listVo(request);
    }


    @ApiOperation("查所有")
    @RequestMapping(value = "/allUserlist", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<UmsAdmin>> allUserlist() {

        List<UmsAdmin> list = adminService.list(new LambdaQueryWrapper<UmsAdmin>()
                .eq(UmsAdmin::getStatus ,1));

        return   CommonResult.success(list);
    }

    @ApiOperation("查询已经绑定的人")
    @RequestMapping(value = "/allUserlistByServiceCode", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<List<UmsAdmin>> allUserlistByServiceCode(@RequestBody UserPriceRuleRelationParam userPriceRuleRelationParam) {
        List<UmsAdmin> umsAdminList=new ArrayList<>();
        List<UmsAdminPriceRuleRelation> list = umsAdminPriceRuleRelationService.list(new LambdaQueryWrapper<UmsAdminPriceRuleRelation>()
                .eq(UmsAdminPriceRuleRelation::getServiceCode ,userPriceRuleRelationParam.getServiceCode()));
        if (!CollectionUtils.isEmpty(list)){

            List<Integer> userIdList = list.stream().map(UmsAdminPriceRuleRelation::getUserId).collect(Collectors.toList());
             umsAdminList = adminService.list(new LambdaQueryWrapper<UmsAdmin>().in(UmsAdmin::getId, userIdList));
        }
        return   CommonResult.success(umsAdminList);
    }


    @ApiOperation("添加用户与价格表的关系")
    @RequestMapping(value = "/addUserPriceRuleRelation", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addUserPriceRuleRelation(@RequestBody UserPriceRuleRelationParam userPriceRuleRelationParam) {
        List<UmsAdminPriceRuleRelation> oneList = new ArrayList<>();


        List<Integer> userUnderSellerlist = null;
        if (userPriceRuleRelationParam.getStaff()!=null) {
            //查出销售所有的用户
            List<UmsAdmin> umsAdminList = adminService.list(new LambdaQueryWrapper<UmsAdmin>()
                    .eq(UmsAdmin::getSellerId, userPriceRuleRelationParam.getStaff()));
            userUnderSellerlist = umsAdminList.stream().map(UmsAdmin::getId).collect(Collectors.toList());

        }
        List<Integer>  allUserlist = new ArrayList<>();
        if (userUnderSellerlist!= null) {

            allUserlist.addAll(userUnderSellerlist);
        }
        if (userPriceRuleRelationParam.getUserIds()!= null) {

            allUserlist.addAll(userPriceRuleRelationParam.getUserIds());
        }

        //批量写入
        for (Integer userId : allUserlist) {
            UmsAdminPriceRuleRelation umsAdminPriceRuleRelation = new UmsAdminPriceRuleRelation();
            umsAdminPriceRuleRelation.setUserId(userId);
            umsAdminPriceRuleRelation.setServiceCode(userPriceRuleRelationParam.getServiceCode());
//            umsAdminPriceRuleRelation.setChannelPlatformId(userPriceRuleRelationParam.getChannelPlatformId());
            oneList.add(umsAdminPriceRuleRelation);
        }

        umsAdminPriceRuleRelationService.saveBatch(oneList);
        return CommonResult.success();
    }
    @ApiOperation("删除用户与价格表的关系")
    @RequestMapping(value = "/delUserPriceRuleRelation", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delUserPriceRuleRelation(@RequestBody UserPriceRuleRelationParam userPriceRuleRelationParam) {

        LambdaUpdateWrapper<UmsAdminPriceRuleRelation> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(UmsAdminPriceRuleRelation::getUserId, userPriceRuleRelationParam.getUserId());
        updateWrapper.eq(UmsAdminPriceRuleRelation::getServiceCode, userPriceRuleRelationParam.getServiceCode());
        updateWrapper.set(UmsAdminPriceRuleRelation::getDeletedAt, new Date());

        umsAdminPriceRuleRelationService.update(updateWrapper);
        return CommonResult.success();
    }





    @ApiOperation("导出")
    @RequestMapping(value = "/down", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<String> down(UmsAdminListParam request) {
        request.setMemberType(MemberType.USER);
        return adminService.down(request);
    }

    @ApiOperation("获取指定用户信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<UmsAdminVO> getItem(@PathVariable Integer id) {
        UmsAdmin admin = adminService.getById(id);
        UmsAdminVO umsAdminVO = new UmsAdminVO();
        BeanUtils.copyProperties(admin, umsAdminVO);


        List<UmsRole> roleList = adminService.getRoleList(id);
        if (CollUtil.isNotEmpty(roleList)) {
            List<String> roles = roleList.stream().map(x -> {
                return x.getId().toString();
            }).collect(Collectors.toList());
            umsAdminVO.setRoles(roles);
        }
        return CommonResult.success(umsAdminVO);
    }

    @ApiOperation("修改指定用户信息")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable Integer id, @RequestBody AdminUpdateRequest request) {

        UmsAdmin umsAdmin = new UmsAdmin();
        BeanUtils.copyProperties(request,umsAdmin);
        boolean success = adminService.update(id, umsAdmin);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @Nullable
    private UmsAdmin getUmsAdmin(Integer id) {
        UmsAdmin umsAdmin = adminService.getOne(new LambdaQueryWrapper<UmsAdmin>().eq(UmsAdmin::getId, id)
                .eq(UmsAdmin::getMemberType, MemberType.USER)
        );
        if (umsAdmin == null) {
            CommonResult.failed("非法操作");
        }
        return umsAdmin;
    }

    @ApiOperation("修改指定用户信息")
    @RequestMapping(value = "/update/seller", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateSeller(@RequestBody @Validated AllotSellerRequest request) {

        // 管理员可以修改余额

        List<Integer> userIds = request.getUserIds();
        if (CollectionUtil.isEmpty(userIds)) {
            return CommonResult.failed();
        }

        adminService.update(new LambdaUpdateWrapper<UmsAdmin>().in(UmsAdmin::getId, userIds).set(UmsAdmin::getSellerId, request.getSellerId()));
        return CommonResult.success();
    }

    @ApiOperation("修改渠道混比")
    @RequestMapping(value = "/channel/updateMixSet", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateMixSet(@RequestBody   List<Channel> request) {
        //只要有一个不为0的就是设置了混比
        boolean isSet = request.stream()
                .anyMatch(channel -> channel.getPlatformRate() != null && channel.getPlatformRate() != 0);


        // 更新渠道
        if (!CollectionUtils.isEmpty(request)) {
            for (Channel channel : request) {
                channelService.update(new LambdaUpdateWrapper<Channel>()
                        .eq(Channel::getId, channel.getId())
                        //如果设置值为1  没设置值为0
                        .set(isSet,Channel::getIsBest, 1)
                        .set(!isSet,Channel::getIsBest, 0)
                        .set(Channel::getPlatformRate, channel.getPlatformRate())
                );
            }
        }

        return CommonResult.success();
    }




    @ApiOperation("获取销售")
    @RequestMapping(value = "/list/seller", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult listSeller() {

        Set<Integer> userIds = umsAdminRoleRelationService.list(new LambdaQueryWrapper<UmsAdminRoleRelation>()
                        .eq(UmsAdminRoleRelation::getRoleId, 9)).stream().map(UmsAdminRoleRelation::getAdminId)
                .filter(Objects::nonNull).collect(Collectors.toSet());
        List<UmsAdmin> list = adminService.list(new LambdaQueryWrapper<UmsAdmin>()
                .in(UmsAdmin::getId, userIds)
                .eq(UmsAdmin::getStatus, 1)
                .select(UmsAdmin::getId, UmsAdmin::getRealName)
        );
        return CommonResult.success(list);
    }

    @ApiOperation("修改指定用户密码")
    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updatePassword(@Validated @RequestBody UpdateAdminPasswordParam updatePasswordParam) {
        int status = adminService.updatePassword(updatePasswordParam);
        if (status > 0) {
            return CommonResult.success(status);
        } else if (status == -1) {
            return CommonResult.failed("提交参数不合法");
        } else if (status == -2) {
            return CommonResult.failed("找不到该用户");
        } else if (status == -3) {
            return CommonResult.failed("旧密码错误");
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("删除指定用户信息")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@PathVariable Integer id) {
        getUmsAdmin(id);

        boolean success = adminService.delete(id);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    @ApiOperation("修改帐号状态")
    @RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateStatus(@PathVariable Integer id, @RequestParam(value = "status") Integer status) {
        getUmsAdmin(id);
        UmsAdmin umsAdmin = new UmsAdmin();
        umsAdmin.setStatus(status);
        boolean success = adminService.update(id, umsAdmin);
        if (success) {
            return CommonResult.success(null);
        }
        return CommonResult.failed();
    }

    /**
     * 用户管理界面按用户释放保证金
     * @param id
     * @return
     */
    @ApiOperation("释放保证金")
    @RequestMapping(value = "/releaseEarnest/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult releaseEarnest(@PathVariable Integer id) {
       return adminService.releaseEarnestAllByUserId(id);
        /*UmsAdmin umsAdmin = adminService.getById(id);
        UserReleaseEarnestRequest userReleaseEarnestRequest = new UserReleaseEarnestRequest();
        userReleaseEarnestRequest.setUserId(id);
        userReleaseEarnestRequest.setEarnest(umsAdmin.getEarnestBalance());
        return adminService.releaseEarnest(userReleaseEarnestRequest);*/
    }

    /**
     * todo 管理员系统管理
     * 快递运单管理 下拉选项中货运不要userid的条件要查全量
     * @param request
     * @return
     */
    @ApiOperation("获取用户运输服务")
    @RequestMapping(value = "/user-channel", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<UserChannelVO>> getUserChannel(@Validated UserChannelRequest request) {

        Integer userId = request.getUserId();
        Page<UserChannel> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<UserChannel> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtils.isNotEmpty(userId),UserChannel::getUserId,userId);
        Page<UserChannel> pageResult = channelUserService.page(page, wrapper);
        Page<UserChannelVO> pageVOResult = new Page<>();
        BeanUtils.copyProperties(pageResult, pageVOResult);
        List<UserChannel> userChannels = pageResult.getRecords();
        List<UserChannelVO> userChannelVOS = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(userChannels)) {

            Set<Integer> userIds = userChannels.stream().map(UserChannel::getUserId).collect(Collectors.toSet());
            Map<Integer, String> userMap = adminService.list(new LambdaQueryWrapper<UmsAdmin>().in(UmsAdmin::getId, userIds))
                    .stream().collect(Collectors.toMap(UmsAdmin::getId, UmsAdmin::getUsername));


            Set<Integer> channelIds = userChannels.stream().map(UserChannel::getChannelId).collect(Collectors.toSet());
            List<Channel> channels = channelService.list(new LambdaQueryWrapper<Channel>()
                    .in(Channel::getId, channelIds)
                    .like(StringUtils.isNotEmpty(request.getChannelName()),Channel::getChannelName,request.getChannelName()));
            Map<Integer, Channel> channelMap = channels.stream()
                    .collect(Collectors.toMap(Channel::getId, Function.identity()));

            Set<Integer> channelPlatformIds = userChannels.stream().map(UserChannel::getChannelPlatformId).collect(Collectors.toSet());
            Map<Integer, String> channelPlatformMap = channelPlatformService.list(new LambdaQueryWrapper<ChannelPlatform>()
                            .in(ChannelPlatform::getId, channelPlatformIds))
                    .stream().collect(Collectors.toMap(ChannelPlatform::getId, ChannelPlatform::getChannelPlatformName));

            Set<Integer> channelCarrierIds = userChannels.stream().map(UserChannel::getChannelCarrierId).collect(Collectors.toSet());
            Map<Integer, String> channelCarrierMap = channelCarrierService.list(new LambdaQueryWrapper<ChannelCarrier>()
                            .in(ChannelCarrier::getId, channelCarrierIds))
                    .stream().collect(Collectors.toMap(ChannelCarrier::getId, ChannelCarrier::getChannelCarrierName));

            for (UserChannel userChannel : userChannels) {
                UserChannelVO userChannelVO = new UserChannelVO();
                BeanUtils.copyProperties(userChannel, userChannelVO);
                userChannelVO.setUsername(userMap.get(userChannelVO.getUserId()));
                Channel channel = channelMap.get(userChannelVO.getChannelId());
                if (channel == null) {
                    continue;
                }
                userChannelVO.setChannelName(channel.getChannelName());
                userChannelVO.setChannelCode(channel.getChannelCode());
                userChannelVO.setChannelPlatFormName(channelPlatformMap.get(channel.getChannelPlatformId()));
                userChannelVO.setChannelCarrierName(channelCarrierMap.get(channel.getChannelCarrierId()));

                //设置servicecode
                userChannelVO.setServiceCode(channel.getServiceCode());
                userChannelVOS.add(userChannelVO);
            }

            pageVOResult.setRecords(userChannelVOS);
        }

        return CommonResult.success(CommonPage.restPage(pageVOResult));
    }

    /**
     * 新版的服务
     * @param request
     * @return
     */
    @ApiOperation("获取新版用户运输服务")
    @RequestMapping(value = "/user-channel-new", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<Map<String, List<UserChannelByServiceCodeVO>>> getUserChannelNew(@Validated UserChannelRequest request) {

        Integer userId = request.getUserId();
        LambdaQueryWrapper<UserChannel> wrapper = new LambdaQueryWrapper<>();
        //userId 必填
        wrapper.eq(UserChannel::getUserId,userId);
        List<UserChannel> userChannels = channelUserService.list( wrapper);
        List<UserChannelByServiceCodeVO> userChannelVOS = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(userChannels)) {

//            Set<Integer> userIds = userChannels.stream().map(UserChannel::getUserId).collect(Collectors.toSet());
//            Map<Integer, String> userMap = adminService.list(new LambdaQueryWrapper<UmsAdmin>().in(UmsAdmin::getId, userIds))
//                    .stream().collect(Collectors.toMap(UmsAdmin::getId, UmsAdmin::getUsername));


            Set<Integer> channelIds = userChannels.stream().map(UserChannel::getChannelId).collect(Collectors.toSet());
            List<Channel> channels = channelService.list(new LambdaQueryWrapper<Channel>()
                    .in(Channel::getId, channelIds)
                    .like(StringUtils.isNotEmpty(request.getChannelName()),Channel::getChannelName,request.getChannelName()));
            Map<Integer, Channel> channelMap = channels.stream()
                    .collect(Collectors.toMap(Channel::getId, Function.identity()));
            //查平台名
            Set<Integer> channelPlatformIds = userChannels.stream().map(UserChannel::getChannelPlatformId).collect(Collectors.toSet());
            Map<Integer, String> channelPlatformMap = channelPlatformService.list(new LambdaQueryWrapper<ChannelPlatform>()
                            .in(ChannelPlatform::getId, channelPlatformIds))
                    .stream().collect(Collectors.toMap(ChannelPlatform::getId, ChannelPlatform::getChannelPlatformName));

            Set<Integer> channelCarrierIds = userChannels.stream().map(UserChannel::getChannelCarrierId).collect(Collectors.toSet());
            Map<Integer, String> channelCarrierMap = channelCarrierService.list(new LambdaQueryWrapper<ChannelCarrier>()
                            .in(ChannelCarrier::getId, channelCarrierIds))
                    .stream().collect(Collectors.toMap(ChannelCarrier::getId, ChannelCarrier::getChannelCarrierName));






            for (UserChannel userChannel : userChannels) {
                UserChannelByServiceCodeVO userChannelVO = new UserChannelByServiceCodeVO();
                BeanUtils.copyProperties(userChannel, userChannelVO);
                Integer channelId = userChannelVO.getChannelId();
//                userChannelVO.setUsername(userMap.get(userChannelVO.getUserId()));
                Channel channel = channelMap.get(channelId);
                if (channel == null) {
                    continue;
                }

                ChannelVO channelVO=new ChannelVO();
                channelVO.setIsBest(userChannel.getIsBest());
                channelVO.setPlatformRate(userChannel.getPlatformRate());
                channelVO.setChannelPlatformName(channelPlatformMap.get(channel.getChannelPlatformId()));
                channelVO.setChannelName(channel.getChannelName());

                userChannelVO.setChannel(channelVO);
                //设置servicecode
                userChannelVO.setServiceCode(channel.getServiceCode());
                userChannelVOS.add(userChannelVO);
            }

            Map<String, List<UserChannelByServiceCodeVO>> groupedChannels = userChannelVOS.stream()
                    .collect(Collectors.groupingBy(UserChannelByServiceCodeVO::getServiceCode));
            return CommonResult.success(groupedChannels);
        }


        return CommonResult.success();

    }
    /**
     * 新版的服务
     * @param request
     * @return
     */
    @ApiOperation("获取新版用户运输服务")
    @RequestMapping(value = "/user-carrier-sever", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult< List<String>> getUserCarrierSever(@Validated UserChannelRequest request) {
        Integer userId = AdminUserUtil.getUserId();
        LambdaQueryWrapper<UserChannel> wrapper = new LambdaQueryWrapper<>();
        //userId 必填
        wrapper.eq(UserChannel::getUserId,userId);
        List<UserChannel> userChannels = channelUserService.list( wrapper);
        if (CollectionUtil.isNotEmpty(userChannels)) {


            Set<Integer> channelIds = userChannels.stream().map(UserChannel::getChannelId).collect(Collectors.toSet());
            //授权中哪些是有效的
            LambdaQueryWrapper<Channel> eq = new LambdaQueryWrapper<Channel>()
                    .in(Channel::getId, channelIds)
                    .eq(Channel::getStatus, ChannelStatus.ON);
            List<Channel> channels = channelService.list(eq);
            //所有相关的servicecode
            List<String> collect = channels.stream().map(Channel::getServiceCode).distinct().collect(Collectors.toList());

            return CommonResult.success(collect);
        }


        return CommonResult.success();

    }


    @ApiOperation("分配用户运输服务")
    @RequestMapping(value = "/channel/allot-channel", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<Channel>> allotChannel(@Validated @RequestBody AllotChannelRequest request) {
        request.setMemberType(MemberType.USER);
        return adminService.allotChannel(request);
    }

    @ApiOperation("根据登录用户角色获取用户不同消费额和订单数")
    @PostMapping("/salesAndOrders")
    @ResponseBody
    public CommonResult<StatisticsOrderDto> getSalesAndOrdersByRole() {
        return adminService.getSalesAndOrdersByRole();
    }



    @ApiOperation("财务1-当月每日订单数和金额统计曲线图")
    @PostMapping("/getDailyOrderQuantity")
    @ResponseBody
    public CommonResult< List<DailyOrderAmountVO> > getDailyOrderQuantity(@Validated @RequestBody(required = false) CompanySellerProfitParam choseMonth) {
        List<DailyOrderAmountVO> dailyOrderQuantity = orderService.getDailyOrderQuantity(choseMonth);
        return CommonResult.success(dailyOrderQuantity);
    }


    @ApiOperation("每月各销售名下客户按天金额")
    @PostMapping("/dailyAmountGroupBySeller")
    @ResponseBody
    public CommonResult< Map<Integer, List<DailyOrderAmountGroupbySellerVO>>  > dailyAmountGroupBySeller() {

        //按天统计销售关联的业绩
        List<DailyOrderAmountGroupbySellerVO> dailyOrderQuantity = orderService.dailyAmountGroupBySeller();

        String[] wzNiNaEmails = new String[]{WZ_EMAIL, WZ_EMAIL2, NINA_EMAIL};
        List<UmsAdmin> wzNiNaIds = adminService.list(new LambdaQueryWrapper<UmsAdmin>().in(UmsAdmin::getEmail, Arrays.asList(wzNiNaEmails)).eq(UmsAdmin::getStatus, ChannelStatus.ON).select(UmsAdmin::getId, UmsAdmin::getEmail));
        List<UmsAdmin> wzNiNaInfo = Optional.ofNullable(wzNiNaIds).orElse(Lists.newArrayList());
        // 拿到汪总的id
        Integer wzId = wzNiNaInfo.stream().filter(umsAdmin -> umsAdmin.getEmail().equals(WZ_EMAIL)).findFirst().orElse(new UmsAdmin()).getId();
        // 拿到nina的id
        Integer ninaId = wzNiNaInfo.stream().filter(umsAdmin -> umsAdmin.getEmail().equals(NINA_EMAIL)).findFirst().orElse(new UmsAdmin()).getId();
        // 拿到汪总第二个邮箱的id
        Integer wzId2 = wzNiNaInfo.stream().filter(umsAdmin -> umsAdmin.getEmail().equals(WZ_EMAIL2)).findFirst().orElse(new UmsAdmin()).getId();
        // 统计的订单里的所有 seller_id
        List<Integer> sellerIdList = dailyOrderQuantity.stream().map(DailyOrderAmountGroupbySellerVO::getSellerId).distinct().collect(Collectors.toList());

        // 看王总两个账号哪个没在统计数据里 单独拿该账号的统计数据
        boolean wzIdExitInStatistics = sellerIdList.stream().anyMatch(sellerId -> sellerId.equals(wzId));
        List<DailyOrderAmountGroupbySellerVO> wzSellerPerformanceStatistics = Lists.newArrayList();
        List<DailyOrderAmountGroupbySellerVO> wz2SellerPerformanceStatistics = Lists.newArrayList();
        if (!wzIdExitInStatistics) {
            // 统计数据里没WZ_EMAIL账号的统计数据 单独拿统计数据
            wzSellerPerformanceStatistics = Optional.ofNullable(
                    orderService.dailyAmountGroupBySingleSeller(wzId)
            ).orElse(Lists.newArrayList());
        }

        boolean wzId2ExitInStatistics = sellerIdList.stream().anyMatch(sellerId -> sellerId.equals(wzId2));
        if (!wzId2ExitInStatistics) {
            // 统计数据里没WZ_EMAIL2账号的统计数据 单独拿统计数据
            wz2SellerPerformanceStatistics = Optional.ofNullable(
                    orderService.dailyAmountGroupBySingleSeller(wzId2)
            ).orElse(Lists.newArrayList());
        }

        // 将两个id放到所有销售id里后再去重
        sellerIdList.add(wzId2);
        sellerIdList.add(wzId);
        sellerIdList = Optional.of(sellerIdList.stream().distinct().collect(Collectors.toList())).orElse(Lists.newArrayList());

        //查询是否有相同用户名的用户
        List<UmsAdmin> umsAdminList = Lists.newArrayList();
        Map<Integer, String> map = MapUtil.newHashMap();
        if (CollectionUtil.isNotEmpty(sellerIdList)) {
            umsAdminList = adminService.list(new LambdaQueryWrapper<UmsAdmin>()
                    .in(UmsAdmin::getId, sellerIdList));
            map = umsAdminList.stream().collect(Collectors.toMap(UmsAdmin::getId, UmsAdmin::getRealName));
        }

        for (DailyOrderAmountGroupbySellerVO vo : dailyOrderQuantity) {
            int sellerId = vo.getSellerId();
            if (ObjectUtil.isNotNull(map)) {
                if (map.containsKey(sellerId)) {
                    vo.setSellerName(map.get(sellerId));
                }
            }
            UmsAdmin sellerInfo = umsAdminList.stream().filter(umsAdmin -> umsAdmin.getId().equals(sellerId)).findFirst().orElse(new UmsAdmin());
            vo.setEmail(sellerInfo.getEmail());
        }
        //List<DailyOrderAmountGroupbySellerVO> completeList = fillMissingDates(dailyOrderQuantity, "2024-07-01", "2024-07-31");

        Map<Integer, List<DailyOrderAmountGroupbySellerVO>> groupedBySellerId = dailyOrderQuantity.stream()
                .collect(Collectors.groupingBy(DailyOrderAmountGroupbySellerVO::getSellerId));

        // 将groupedBySellerId里的 wzId 和 wzId2的数据删除
        // 如果存在 先将groupedBySellerId里的赋值 给存在的那个的id的list
        if (wzIdExitInStatistics) {
            wzSellerPerformanceStatistics = groupedBySellerId.get(wzId);
            groupedBySellerId.remove(wzId);
        }
        if (wzId2ExitInStatistics) {
            wz2SellerPerformanceStatistics = groupedBySellerId.get(wzId2);
            groupedBySellerId.remove(wzId2);
        }

        // 将两个账号数据整合 成一个数据 设置进去
        // 创建一个临时的 Map 来存储每个 sellDate 对应的累加金额
        Map<String, BigDecimal> amountMap = new HashMap<>();
        Map<Integer, List<DailyOrderAmountGroupbySellerVO>> wzStatisticsMap = wzSellerPerformanceStatistics.stream().collect(Collectors.groupingBy(DailyOrderAmountGroupbySellerVO::getSellerId));
        Map<Integer, List<DailyOrderAmountGroupbySellerVO>> wz2StatisticsMap = wz2SellerPerformanceStatistics.stream().collect(Collectors.groupingBy(DailyOrderAmountGroupbySellerVO::getSellerId));

        // 处理 wzStatisticsMap 中的数据
        wzStatisticsMap.getOrDefault(wzId, Lists.newArrayList()).forEach(dailyOrderAmountGroupbySellerVO -> {
            String dateStr = dailyOrderAmountGroupbySellerVO.getDate();
            BigDecimal totalAmount = dailyOrderAmountGroupbySellerVO.getTotalAmount();
            // 使用 merge 方法，如果 dateStr 已存在，则将新的金额与已有的金额相加；否则，直接设置新的金额
            amountMap.merge(dateStr, totalAmount, BigDecimal::add);
        });

        // 处理 wz2StatisticsMap 中的数据
        wz2StatisticsMap.getOrDefault(wzId2, Lists.newArrayList()).forEach(dailyOrderAmountGroupbySellerVO -> {
            String dateStr = dailyOrderAmountGroupbySellerVO.getDate();
            BigDecimal totalAmount = dailyOrderAmountGroupbySellerVO.getTotalAmount();
            // 使用 merge 方法，如果 dateStr 已存在，则将新的金额与已有的金额相加；否则，直接设置新的金额
            amountMap.merge(dateStr, totalAmount, BigDecimal::add);
        });

        UmsAdmin wzInfo = umsAdminList.stream().filter(umsAdmin -> umsAdmin.getId().equals(wzId)).findFirst().orElse(new UmsAdmin());

        Map<Integer, List<DailyOrderAmountGroupbySellerVO>> wzMixStatisticsMap = new HashMap<>();
        // 将累加后的结果转换为新的 SellAmount 对象列表，并获取 m2 中对应 sellDate 的 sellName
        List<DailyOrderAmountGroupbySellerVO> wzMixStatisticsList = amountMap.entrySet().stream()
                .map(entry -> {
                    BigDecimal amount = entry.getValue();
                    String dateStr = entry.getKey();
                    DailyOrderAmountGroupbySellerVO dailyOrderAmountGroupbySellerVO = new DailyOrderAmountGroupbySellerVO();
                    dailyOrderAmountGroupbySellerVO.setSellerId(wzId);
                    dailyOrderAmountGroupbySellerVO.setTotalAmount(amount);
                    dailyOrderAmountGroupbySellerVO.setDate(dateStr);
                    dailyOrderAmountGroupbySellerVO.setSellerName(StrUtil.isNotBlank(wzInfo.getRealName()) ? wzInfo.getRealName() : wzInfo.getUsername());
                    dailyOrderAmountGroupbySellerVO.setEmail(wzInfo.getEmail());
                    return dailyOrderAmountGroupbySellerVO;
                })
                .collect(Collectors.toList());

        // 将新数据存入map
        groupedBySellerId.put(wzId, wzMixStatisticsList);

        Map<Integer, List<DailyOrderAmountGroupbySellerVO>> resultSortedMap = MapUtil.newHashMap();
        //CommonResult.success(sellerPerformanceDtos.stream().sorted((item1, item2) -> item1.getWhichMonth().compareTo(item2.getWhichMonth())).collect(Collectors.toList()));
        groupedBySellerId.forEach((sellerId, dailyAmounts) -> {
            List<DailyOrderAmountGroupbySellerVO> collect = dailyAmounts.stream().sorted(Comparator.comparing(DailyOrderAmountGroupbySellerVO::getDate)).collect(Collectors.toList());
            resultSortedMap.put(sellerId, collect);
        });

        //return CommonResult.success(groupedBySellerId);
        return CommonResult.success(resultSortedMap);
    }
//    public static List<DailyOrderAmountGroupbySellerVO> fillMissingDates(List<DailyOrderAmountGroupbySellerVO> originalList, String startDate, String endDate) {
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        LocalDate start = LocalDate.parse(startDate, formatter);
//        LocalDate end = LocalDate.parse(endDate, formatter);
//
//        Map<currentDate, DailyOrderAmountGroupbySellerVO> dateToOrderAmountMap = new HashMap<>();
//        for (DailyOrderAmountGroupbySellerVO vo : originalList) {
//            dateToOrderAmountMap.put(vo.getDate(), vo);
//        }
//
//        List<DailyOrderAmountGroupbySellerVO> completeList = new ArrayList<>();
//        LocalDate currentDate = start;
//
//        while (!currentDate.isAfter(end)) {
////            String currentDateString = currentDate.format(formatter);
//            DailyOrderAmountGroupbySellerVO vo = dateToOrderAmountMap.getOrDefault(currentDateString, new DailyOrderAmountGroupbySellerVO( 0, currentDate));
//            completeList.add(vo);
//            currentDate = currentDate.plusDays(1);
//        }
//
//        return completeList;
//    }

    @ApiOperation("各销售名下客户当日总打单金额和利润")
    @PostMapping("/sellerUserDayStatistics")
    @ResponseBody
    public CommonResult<List<SellerUserGroupDto>> getSellerUserOrderStatistics(@RequestBody(required = false) SellerUserDayParam sellerUserDayParam) {
        return adminService.getSellerUserOrderStatistics(sellerUserDayParam);
    }

    @ApiOperation("每月公司总业绩和各个销售的总业绩")
    @PostMapping("/sellerPerformanceStatistics")
    @ResponseBody
    public CommonResult<List<SellerPerformanceDto>> getStatistics(@Validated @RequestBody(required = false) CompanySellerProfitParam choseMonth) {
        return adminService.getSellerPerformanceStatistics(choseMonth);
    }

    @ApiOperation("所有销售")
    @PostMapping("/allSellers")
    @ResponseBody
    public CommonResult<List<SellerVo>> getAllEnableSellers() {
        return adminService.getAllEnableSellers();
    }

    @ApiOperation("所有销售")
    @GetMapping("/pageOWUser")
    @ResponseBody
    public CommonResult<CommonPage<UmsAdminVO>> pageOWUser(UmsAdminListParam request) {
        request.setMemberType(MemberType.OUT_SEA_USER);
        return adminService.listVo(request);
    }


    @ApiOperation(value = "海外仓用户注册")
    @PostMapping("/overSeasRegister")
    @ResponseBody
    public CommonResult<UmsAdmin> overSeasRegister(@Validated @RequestBody OverseasUserAddParam overseasUserAddParam) {
        UmsAdmin umsAdmin = adminService.overseasUserRegister(overseasUserAddParam);
        if (umsAdmin == null) {
            return CommonResult.failed();
        }
        return CommonResult.success(umsAdmin);
    }

    @ApiOperation("海外仓用户导出")
    @GetMapping("/overSeasDown")
    @ResponseBody
    public CommonResult<String> overSeasDown(UmsAdminListParam request) {
        return adminService.down(request);
    }

    /**
     * @Author: hhp
     * @Description: user-channel 有另外三个页面用到 重起一个方法避免影响其他页面
     * userManagement.vue employeeManagement.vue overseasWarehouseUser.vue
     * @Data: 2024/8/27 14:14
     * @param com.jinke.api.modules.ums.request.UserChannelRequest request
     * @return: com.jinke.api.common.api.CommonResult<com.jinke.api.common.api.CommonPage<com.jinke.api.modules.ums.vo.UserChannelVO>>
     * @throws:
     **/
    @ApiOperation("获取所有用户运输服务")
    @GetMapping("/all-user-channel")
    @ResponseBody
    public CommonResult<CommonPage<UserChannelVO>> getAllUserChannel(@Validated UserChannelRequest request) {
        // 前端只需要channelId channelName 分页拿的下拉数据 直接去重
        // 根据channelId 去重，这里可以从channel表拿所有.
        //wrapper.eq(ObjectUtils.isNotEmpty(userId),UserChannel::getUserId,userId);
        Page<UserChannel> pageResult = channelUserService.page(
                new Page<>(request.getPageNum(), request.getPageSize()),
                Wrappers.<UserChannel>lambdaQuery()
                        .select(UserChannel::getChannelId, UserChannel::getUserId, UserChannel::getChannelCarrierId,
                                UserChannel::getChannelPlatformId));
        Page<UserChannelVO> pageVOResult = new Page<>();
        BeanUtils.copyProperties(pageResult, pageVOResult);

        // 根据channelId 去重
        // 处理key冲突的情况，这里选择保留第一个出现的
        Map<Integer, UserChannel> uniqueChannelsMap = Optional.of(pageResult.getRecords().stream()
                .collect(Collectors.toMap(UserChannel::getChannelId, u -> u,
                        (u1, u2) -> u1))).orElse(Maps.newHashMap());
        List<UserChannel> userChannels = new ArrayList<>(uniqueChannelsMap.values());

        //List<UserChannel> userChannels = pageResult.getRecords();
        List<UserChannelVO> userChannelVOS = Lists.newArrayList();
        if (CollectionUtil.isNotEmpty(userChannels)) {

            Set<Integer> channelIds = userChannels.stream().map(UserChannel::getChannelId).collect(Collectors.toSet());
            List<Channel> channels = channelService.list(new LambdaQueryWrapper<Channel>()
                    .in(Channel::getId, channelIds)
                    .like(StringUtils.isNotEmpty(request.getChannelName()),Channel::getChannelName,request.getChannelName()));
            Map<Integer, Channel> channelMap = channels.stream()
                    .collect(Collectors.toMap(Channel::getId, Function.identity()));

            List<UserChannelVO> userChannelVOList = userChannels.stream().filter(userChannel -> ObjectUtil.isNotNull(channelMap.get(userChannel.getChannelId()))).map(userChannel -> {
                UserChannelVO userChannelVO = new UserChannelVO();
                BeanUtils.copyProperties(userChannel, userChannelVO);
                Channel channel = channelMap.get(userChannelVO.getChannelId());
                userChannelVO.setChannelName(channel.getChannelName());
                userChannelVO.setChannelCode(channel.getChannelCode());
                //设置servicecode
                userChannelVO.setServiceCode(channel.getServiceCode());
                return userChannelVO;
            }).collect(Collectors.toList());
            userChannelVOS.addAll(userChannelVOList);
            pageVOResult.setRecords(userChannelVOS);
        }

        return CommonResult.success(CommonPage.restPage(pageVOResult));
        /*Integer userId = request.getUserId();
        Page<UserChannel> page = new Page<>(request.getPageNum(), request.getPageSize());
        LambdaQueryWrapper<UserChannel> wrapper = new LambdaQueryWrapper<>();
        //wrapper.eq(ObjectUtils.isNotEmpty(userId),UserChannel::getUserId,userId);
        Page<UserChannel> pageResult = channelUserService.page(page, wrapper);
        Page<UserChannelVO> pageVOResult = new Page<>();
        BeanUtils.copyProperties(pageResult, pageVOResult);
        List<UserChannel> userChannels = pageResult.getRecords();
        List<UserChannelVO> userChannelVOS = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(userChannels)) {

            Set<Integer> userIds = userChannels.stream().map(UserChannel::getUserId).collect(Collectors.toSet());
            Map<Integer, String> userMap = adminService.list(new LambdaQueryWrapper<UmsAdmin>().in(UmsAdmin::getId, userIds))
                    .stream().collect(Collectors.toMap(UmsAdmin::getId, UmsAdmin::getUsername));


            Set<Integer> channelIds = userChannels.stream().map(UserChannel::getChannelId).collect(Collectors.toSet());
            List<Channel> channels = channelService.list(new LambdaQueryWrapper<Channel>()
                    .in(Channel::getId, channelIds)
                    .like(StringUtils.isNotEmpty(request.getChannelName()),Channel::getChannelName,request.getChannelName()));
            Map<Integer, Channel> channelMap = channels.stream()
                    .collect(Collectors.toMap(Channel::getId, Function.identity()));

            Set<Integer> channelPlatformIds = userChannels.stream().map(UserChannel::getChannelPlatformId).collect(Collectors.toSet());
            Map<Integer, String> channelPlatformMap = channelPlatformService.list(new LambdaQueryWrapper<ChannelPlatform>()
                            .in(ChannelPlatform::getId, channelPlatformIds))
                    .stream().collect(Collectors.toMap(ChannelPlatform::getId, ChannelPlatform::getChannelPlatformName));

            Set<Integer> channelCarrierIds = userChannels.stream().map(UserChannel::getChannelCarrierId).collect(Collectors.toSet());
            Map<Integer, String> channelCarrierMap = channelCarrierService.list(new LambdaQueryWrapper<ChannelCarrier>()
                            .in(ChannelCarrier::getId, channelCarrierIds))
                    .stream().collect(Collectors.toMap(ChannelCarrier::getId, ChannelCarrier::getChannelCarrierName));

            for (UserChannel userChannel : userChannels) {
                UserChannelVO userChannelVO = new UserChannelVO();
                BeanUtils.copyProperties(userChannel, userChannelVO);
                userChannelVO.setUsername(userMap.get(userChannelVO.getUserId()));
                Channel channel = channelMap.get(userChannelVO.getChannelId());
                if (channel == null) {
                    continue;
                }
                userChannelVO.setChannelName(channel.getChannelName());
                userChannelVO.setChannelCode(channel.getChannelCode());
                userChannelVO.setChannelPlatFormName(channelPlatformMap.get(channel.getChannelPlatformId()));
                userChannelVO.setChannelCarrierName(channelCarrierMap.get(channel.getChannelCarrierId()));

                //设置servicecode
                userChannelVO.setServiceCode(channel.getServiceCode());
                userChannelVOS.add(userChannelVO);
            }

            pageVOResult.setRecords(userChannelVOS);
        }

        return CommonResult.success(CommonPage.restPage(pageVOResult));*/
    }
}
